#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=200;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct Tree{
   LL l,r,id;
}tree[maxn];
LL a[maxn];
LL dep[maxn];
map<LL,LL>map1;
LL tot=0;
LL build(LL l,LL r,LL n){
    if(l>n||r<1) return -1;
    if(l>r) return -1;
    if(l==r){
        ++tot;
        tree[tot].l=tree[tot].r=-1;
        tree[tot].id=a[l];
        return tot;
    }
    ++tot;
    LL rt=tot;
    LL ans=0;LL pos=0;
    for(LL i=l;i<=r;i++){
        if(ans<a[i]){
            ans=a[i];
            pos=i;
        }
    }
    tree[rt].id=ans;
    tree[rt].l=build(l,pos-1,n);
    tree[rt].r=build(pos+1,r,n);
    return rt;
}
void dfs(LL u,LL fa){
    dep[u]=dep[fa]+1;
    map1[tree[u].id]=dep[u];
    if(tree[u].l!=-1){
        dfs(tree[u].l,u);
    }
    if(tree[u].r!=-1){
        dfs(tree[u].r,u);
    }
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n;cin>>n;
    tot=0;
    for(LL i=1;i<=n;i++) cin>>a[i];
    memset(tree,0,sizeof(tree));
    memset(dep,0,sizeof(dep));
    map1.clear();
    build(1,n,n);
    dep[0]=-1;
    dfs(1,0);
    for(LL i=1;i<=n;i++){
        cout<<map1[a[i]]<<" ";
    }
    cout<<"\n";
  }
return 0;
}
